package com.pennywise.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.awt.*;
import java.awt.TrayIcon.MessageType;

/**
 * Windows系统通知服务
 */
@Slf4j
@Service
public class NotificationService {
    
    private TrayIcon trayIcon;
    
    public NotificationService() {
        initializeTrayIcon();
    }
    
    private void initializeTrayIcon() {
        try {
            if (SystemTray.isSupported()) {
                SystemTray tray = SystemTray.getSystemTray();
                Image image = Toolkit.getDefaultToolkit().createImage("icon.png");
                trayIcon = new TrayIcon(image, "PennyWise");
                trayIcon.setImageAutoSize(true);
                tray.add(trayIcon);
                log.info("系统托盘图标初始化成功");
            } else {
                log.warn("系统不支持托盘图标");
            }
        } catch (Exception e) {
            log.error("初始化系统托盘图标失败", e);
        }
    }
    
    /**
     * 发送系统通知
     *
     * @param title 通知标题
     * @param message 通知内容
     */
    public void sendNotification(String title, String message) {
        try {
            if (trayIcon != null) {
                trayIcon.displayMessage(title, message, MessageType.INFO);
                log.debug("发送系统通知: {} - {}", title, message);
            } else {
                log.warn("系统托盘图标未初始化，无法发送通知");
            }
        } catch (Exception e) {
            log.error("发送系统通知失败", e);
        }
    }
} 